package com.iqismart.shorturl.websocket;

import java.io.Serializable;

/**
 * @Description
 * @Auther sty
 * @createTime 2019-01-14 10:10
 */
public class Message implements Serializable {

    private static final long serialVersionUID = 4759811720365143560L;
    private String message;
    private String fromUserName;
    private String toUserName;
    private Long from = 0L;
    private Long to = 0L;
    private Long hiddenForUid;
    private String hiddenForUserName;
    private Long createTime = System.currentTimeMillis();
    private String createTimeString = "";

    /**
     * 返回与当前时间相比，几秒前，几分钟前，几小时前，几天前，几月前，几年前
     *
     * @param time
     * @return
     */
    public static String formatTimeDifference(long time)throws Exception {
        // 2012-9-10 18:26:06 修改，一分钟之内，都是刚刚, 最多只有几天前
        long diff = (System.currentTimeMillis() - time) / 1000;
        if (diff <= 0) {
            return "刚刚";
        } else if (diff < 60) {
            // return diff + "秒前";
            return "刚刚";
        } else if (diff < 60 * 60) {
            return (diff / 60) + "分钟前";
        } else if (diff < 60 * 60 * 24) {
            return (diff / 60 / 60) + "小时前";
            // } else if (diff < 60 * 60 * 24 * 30) {
        } else {
            return (diff / 60 / 60 / 24) + "天前";
            // } else if (diff < 60 * 60 * 24 * 30 * 12) {
            // return (diff / 60 / 60 / 24 / 30) + "月前";
            // } else {
            // return (diff / 60 / 60 / 24 / 30 / 12) + "年前";
        }
    }

    public String getCreateTimeString() {

        try {
            return formatTimeDifference(createTime);
        } catch (Exception e) {
        }
        return createTimeString;
    }

    public void setCreateTimeString(String createTimeString) {
        this.createTimeString = createTimeString;
    }

    public Message() {
    }

    public Message(String message, Long hiddenForUid, String hiddenForUserName) {
        this.message = message;
        this.hiddenForUid = hiddenForUid;
        this.hiddenForUserName = hiddenForUserName;
    }

    public Message(String message, Long hiddenForUid) {
        this.message = message;
        this.hiddenForUid = hiddenForUid;
    }


    public Message(String message) {
        this.message = message;
    }


    public String getFromUserName() {
        return fromUserName;
    }

    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getHiddenForUserName() {
        return hiddenForUserName;
    }

    public void setHiddenForUserName(String hiddenForUserName) {
        this.hiddenForUserName = hiddenForUserName;
    }

    public Long getHiddenForUid() {
        return hiddenForUid;
    }

    public void setHiddenForUid(Long hiddenForUid) {
        this.hiddenForUid = hiddenForUid;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Long getFrom() {
        return from;
    }

    public void setFrom(Long from) {
        this.from = from;
    }

    public Long getTo() {
        return to;
    }

    public void setTo(Long to) {
        this.to = to;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }
}
